export const GET_MENU_LIST_REQUEST = 'GET_MENU_LIST_REQUEST'
export const GET_MENU_LIST_SUCCESS = 'GET_MENU_LIST_SUCCESS'
export const GET_MENU_LIST_FAILURE = 'GET_MENU_LIST_FAILURE'

export function getMenuListRequest() {
    return {
        type: GET_MENU_LIST_REQUEST
    }
}

export function getMenuListSuccess(list) {
        return {
            type: GET_MENU_LIST_SUCCESS,
            payload: list
        }
}

export function getMenuListFailure(error) {
    return {
        type: GET_MENU_LIST_FAILURE,
        error: error
    }
}

export function getMenuList() {
    return function(dispatch) {
        dispatch(getMenuListRequest);
        fetch('/api/menu-list.json')
        .then((res) => {
            let list = res.json();
            return list
        })
        .then((list) => {
            dispatch(getMenuListSuccess(list));
        })
        .catch((e) => {
            dispatch(getMenuListFailure(e))
        })
    }
}